home *** CD-ROM | disk | FTP | other *** search
Wrap
/* ** authored by rue */ /* Pre-Install Cleanup (for prior versions) */ // temp-dir initInstall("pre-install", "/tempDir", "0.0"); // dummy-install - allows committance of file-operations var tempDir = getFolder(getFolder("Profile", "chrome"), "adblock-temp"); // adblock temp-dir if (!File.exists(tempDir)) dirCreate(tempDir); // create temp-dir if it doesn't exist performInstall(); // commit dir-creation changes // file-check array var dirArray = new Array(); dirArray[0] = new Array(); dirArray[0].push(getFolder("Profile", "chrome")); // profile-chrome dirArray[0].push("adblock"); // filename - profile jar dirArray[0].push(".jar"); // filename - extension dirArray[1] = new Array(); dirArray[1].push(getFolder("chrome")); // app-chrome dirArray[1].push("adblock"); // filename - root jar dirArray[1].push(".jar"); // filename - extension dirArray[2] = new Array(); dirArray[2].push(getFolder("components")); // app-components dirArray[2].push("nsAdblock"); // filename - root component dirArray[2].push(".js"); // filename - extension dirArray[3] = new Array(); dirArray[3].push(getFolder("Profile")); // profile dirArray[3].push("XUL FastLoad File"); // filename - xul cache mac dirArray[3].push(""); // filename - extension dirArray[4] = new Array(); dirArray[4].push(getFolder("Profile")); // profile dirArray[4].push("XUL"); // filename - xul cache macosX dirArray[4].push(".mfast"); // filename - extension dirArray[5] = new Array(); dirArray[5].push(getFolder("Profile")); // profile dirArray[5].push("XUL"); // filename - xul cache linux dirArray[5].push(".mfasl"); // filename - extension dirArray[6] = new Array(); dirArray[6].push(getFolder("Profile")); // profile dirArray[6].push("XUL"); // filename - xul cache windows dirArray[6].push(".mfl"); // filename - extension // file-check loop for (var i = 0 ; i < dirArray.length ; i++) { initInstall("pre-install", "/rename", "0."+i); // reopen dummy-install var currentDir = dirArray[i][0]; var nameMain = dirArray[i][1]; var nameEnd = dirArray[i][2]; var tempDir = getFolder(getFolder("Profile", "chrome"), "adblock-temp"); // adblock temp-dir if (!File.exists(tempDir)) dirCreate(tempDir); // create temp-dir if it doesn't exist var previousFile = getFolder(currentDir, nameMain + nameEnd); // previous jar var newNameMain = "adblock-uninstalled";// nameMain + "-uninstalled"; var newName = newNameMain; // + nameEnd; var n = 1; if (File.exists(previousFile)) { if (File.exists(getFolder(currentDir, newName))) // <-- change 'currentDir' to 'tempDir' to revert: old-style while(File.exists(getFolder(currentDir, newName))) { // <-- ditto. newName = new String(newNameMain + n); // + nameEnd); // find a unique-name for our "move-to" destination n++; } // rename file File.rename(previousFile, newName); // rename the previous jar to the unique-name performInstall(); // commit file-rename changes // -- this can be (un)commented without worry.. it just seemingly fails to move, every time // move file initInstall("pre-install", "/move", "0."+i); // reopen dummy-install previousFile = getFolder(currentDir, newName); // get prev. version by its new name File.move(previousFile, tempDir); // move jar to temp-dir performInstall(); // commit file-move changes // delete original initInstall("pre-install", "/delete", "0."+i); // reopen dummy-install if (File.exists(previousFile)) File.remove(previousFile); // delete original (in case it didn't completely move) performInstall(); // commit file-deletion changes } } /* Main Install Routine */ // only load after the Pre-Install Cleanup completes if (true) { // install constants const APP_DISPLAY_NAME = "Adblock"; const APP_NAME = "adblock"; const APP_PACKAGE = "/adblock.mozdev.org"; const APP_VERSION = "0.5"; const APP_JAR_FILE = "adblock.jar"; const APP_JAR_LOC = 'chrome/' + APP_JAR_FILE; const APP_COMP_FILE = "nsAdblock.js"; const APP_COMP_LOC = APP_COMP_FILE; const APP_CONTENT_FOLDER = "content/"; const INST_TO_PROFILE = "Install "+APP_DISPLAY_NAME+" in your profile?\n(..you wont have to reinstall when updating the browser).\n\nClick Cancel to install "+APP_DISPLAY_NAME+" in the browser root."; const ROOT_FAILED___TRY_INST_TO_PROFILE = "You didn't have permission to install as root.\n Would you like to force profile-installation?\n\n[Note: "+APP_DISPLAY_NAME+" WILL NOT FUNCTION in the profile for browsers-builds older than 6.24.03. This includes moz1.4.1 and fb.6]"; const profileChrome = getFolder("Profile", "chrome"); const previousJarInProfile = getFolder(profileChrome, "adblock.jar"); const previousJarInRoot = getFolder("chrome", "adblock.jar"); } // initialize our install initInstall(APP_NAME, APP_PACKAGE, APP_VERSION); // check for previous install if (File.exists(previousJarInProfile) || File.exists(previousJarInRoot)) { var installedHere = File.exists(previousJarInProfile)?"profile ":""; installedHere += (File.exists(previousJarInProfile) && File.exists(previousJarInRoot))?"*and* ":""; installedHere += File.exists(previousJarInRoot)?"root ":""; installedHere += (File.exists(previousJarInProfile) && File.exists(previousJarInRoot))?"directories":"directory"; alert("Sorry: Adblock is already installed in your " + installedHere + ". " +"\n\n\n\nIf you're running a recent dev-build, you can deinstall from preferences. " +"\nFor all other versions, please consult the online-faq:" +"\n\nadblock.mozdev.org/faq.html"); cancelInstall(-23); // we can't overwrite, so don't install further } else { // runtime component registration only works since 2003-06-24.. var instToProfile = false; if (buildID == 0 || buildID > 2003062400) instToProfile = confirm(INST_TO_PROFILE); // ..so, dont ask on prior builds. // install component if not installing to profile if (!instToProfile) { var compf = getFolder("components"); var errComponent = addFile(APP_PACKAGE, APP_VERSION, APP_COMP_LOC, compf, null); } // install jar-file var chromef = instToProfile ? getFolder("Profile", "chrome") : getFolder("chrome"); var errJar = addFile(APP_PACKAGE, APP_VERSION, APP_JAR_LOC, chromef, null); // if root-install was attempted and failed, ask the user what to do if(!instToProfile && (errComponent != SUCCESS || errJar != SUCCESS)) { instToProfile = confirm(ROOT_FAILED___TRY_INST_TO_PROFILE); if (instToProfile) { chromef = getFolder("Profile", "chrome"); errJar = addFile(APP_PACKAGE, APP_VERSION, APP_JAR_LOC, chromef, null); } else errJar = "root install failed"; } // if we've successfully installed the files, register them if (errJar == SUCCESS) { var jar = getFolder(chromef, APP_JAR_FILE); if (instToProfile) registerChrome(CONTENT | PROFILE_CHROME, jar, APP_CONTENT_FOLDER); else registerChrome(CONTENT | DELAYED_CHROME, jar, APP_CONTENT_FOLDER); var err = performInstall(); if (err == SUCCESS || err == 999) { alert(APP_DISPLAY_NAME + " " + APP_VERSION + " is now installed.\n" +"Just restart to activate."); } else { alert("Install failed. Error code:" + err); cancelInstall(err); } } else { alert("Failed to create " +APP_JAR_FILE +"\n" +"You probably don't have appropriate permissions \n" +"(write access to your profile or chrome directory). \n" +"_____________________________\nError code:" + errJar); cancelInstall(errJar); } }